﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using BusinessLogicLibrary;
using entities;

namespace ServiceLibrary
{
    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    public class ManagerService : IManagerService
    {
        private readonly EmployeeModule _employee = new EmployeeModule();
        private readonly PromotionModule _promotion = new PromotionModule();
        private readonly ReportModule _report = new ReportModule();
        private readonly RoomModule _room = new RoomModule();
        private readonly SupplyModule _supply = new SupplyModule();

        #region"EMPLOYEE Management"

        public bool EmployeeEmailCheck(string email)
        {
            try
            {
                return _employee.CheckEmployeeEmail(email);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public bool EmployeeAdd(string name, bool sex, DateTime birthday, string position, string phone, string email,
                                string address, string city, string country, string jobtitle, byte[] image)
        {
            try
            {
                return _employee.AddEmployee(name, sex, birthday, position, phone, email, address, city, country,
                                             jobtitle, image);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public bool EmployeeModify(int employeeID, string name, bool sex, DateTime birthday, string position,
                                   string phone, string email, string address, string city, string country,
                                   string jobtitle,
                                   byte[] image)
        {
            try
            {
                return _employee.ModifyEmployee(employeeID, name, sex, birthday, position, phone, email, address,
                                                city, country, jobtitle, image);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public bool EmployeeDeactive(int employeeID)
        {
            try
            {
                return _employee.DeactiveEmployee(employeeID);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public List<vEmployeeSubDetail> EmployeesGet(bool all)
        {
            try
            {
                return _employee.GetEmployees(all);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public Employee EmployeeGetById(int employeeID)
        {
            try
            {
                return _employee.GetEmployee(employeeID);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }


        public List<vEmployeeSubDetail> EmployeesGetByName(string employeeName)
        {
            try
            {
                return _employee.GetEmployees(employeeName);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        #endregion

        #region "ROOM Management"

        public bool EquipmentDetailAdd(string name, decimal price, bool available)
        {
            try
            {
                return _room.AddEquipmentDetail(name, price, available);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }


        public List<EquipmentDetail> EquipmentDetailsGet(bool available)
        {
            try
            {
                return _room.GetEquipmentDetails(available);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public EquipmentDetail EquipmentDetailGetById(int equipmentId)
        {
            try
            {
                return _room.GetEquipmentDetail(equipmentId);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public List<EquipmentDetail> EquipmentDetailsGetByName(string name)
        {
            try
            {
                return _room.GetEquipmentDetails(name);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }


        public bool EquipmentDetailModify(int id, string name, decimal price, bool available)
        {
            try
            {
                return _room.ModifyEquipmentDetail(id, name, price, available);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public List<EquipmentDetail> EquipmentDetailsGetByRoomTypeID(int roomTypeId)
        {
            try
            {
                return _room.GetEquipmentDetailsByRoomTypeID(roomTypeId);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public RoomType RoomTypeGetById(int roomTypeId)
        {
            try
            {
                return _room.GetRoomType(roomTypeId);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public List<RoomType> RoomTypeGets()
        {
            try
            {
                return _room.GetRoomTypes();
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public bool RoomTypeAdd(string title, string rank, decimal price, bool bath, bool view, bool balcon,
                                List<int> equipmentDetailID)
        {
            try
            {
                return _room.AddRoomType(title, rank, price, bath, view, balcon, equipmentDetailID);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public bool RoomTypeModify(int id, string title, string rank, decimal price, bool bath, bool view,
                                   bool balcony, List<int> equipmentDetailId)
        {
            try
            {
                return _room.ModifyRoomType(id, title, rank, price, bath, view, balcony, equipmentDetailId);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }


        public List<Room> RoomsGet(int available)
        {
            try
            {
                return _room.GetRooms(available);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public Room RoomGetById(int roomId)
        {
            try
            {
                return _room.GetRoom(roomId);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }


        public List<Room> RoomsGetByRoomTypeId(int roomTypeId)
        {
            try
            {
                return _room.GetRoomsByRoomTypeID(roomTypeId);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public bool RoomAdd(int roomId, int status, int roomTypeId)
        {
            try
            {
                return _room.AddRoom(roomId, status, roomTypeId);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public bool RoomModify(int roomId, int status, int roomTypeId)
        {
            try
            {
                return _room.ModifyRoom(roomId, status, roomTypeId);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        #endregion

        #region "SUPPLY Management"

        public bool SupplyDetailAdd(bool available, string supplyName, decimal price, string unit)
        {
            try
            {
                return _supply.AddSupplyDetail(available, supplyName, price, unit);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public bool SupplyDetailModify(int id, bool available, string supplyName, decimal price, string unit)
        {
            try
            {
                return _supply.ModifySupplyDetail(id, available, supplyName, price, unit);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public List<SupplyDetail> SupplyDetailsGet(bool available)
        {
            try
            {
                return _supply.GetSupplyDetails(available);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public SupplyDetail SupplyDetailGetById(int supplyId)
        {
            try
            {
                return _supply.GetSupplyDetail(supplyId);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public List<SupplyDetail> SupplyDetailsGetByName(string supplyDetailName)
        {
            try
            {
                return _supply.GetSupplyDetails(supplyDetailName, false);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        #endregion

        #region "PROMOTION Management"

        public List<vSubPromotion> PromotionsGet(bool available)
        {
            try
            {
                return _promotion.GetPromotions(available);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public Promotion PromotionGetById(int promotionId)
        {
            try
            {
                return _promotion.GetPromotion(promotionId);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public List<vSubPromotion> PromotionsGetByTitle(string promotionTitle)
        {
            try
            {
                return _promotion.GetPromotions(promotionTitle);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public List<vSubPromotion> PromotionsGetByTime(DateTime startTime, DateTime endTime)
        {
            try
            {
                return _promotion.GetPromotions(startTime, endTime);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public bool PromotionAdd(DateTime startTime, DateTime endTime, string title, string desciption, byte[] banner)
        {
            try
            {
                return _promotion.AddPromotion(startTime, endTime, title, desciption, banner);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public bool PromotionModify(int promotionId, DateTime startTime, DateTime endTime, string title,
                                    string desciption,
                                    byte[] banner)
        {
            try
            {
                return _promotion.ModifyPromotion(promotionId, startTime, endTime, title, desciption, banner);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public bool PromotionRemove(int id)
        {
            try
            {
                return _promotion.removePromotion(id);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public List<vSubPromotionDetail> PromotionDetailsGetByPromotionId(int promotionId)
        {
            try
            {
                return _promotion.GetPromotionDetailsByPromotionId(promotionId);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public PromotionDetail PromotionDetailGetById(int promotionDetailId)
        {
            try
            {
                return _promotion.GetPromotionDetail(promotionDetailId);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public bool PromotionDetailAdd(int promotionId, string promotionContent, byte[] promotionImage)
        {
            try
            {
                return _promotion.AddPromotionDetail(promotionId, promotionContent, promotionImage);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public bool PromotionDetailModify(int promotionDetailId, string promotionContent, byte[] promotionImage)
        {
            try
            {
                return _promotion.ModifyPromotionDetail(promotionDetailId, promotionContent, promotionImage);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public bool PromotionDetailRemove(int promotionDetailId)
        {
            try
            {
                return _promotion.RemovePromotionDetail(promotionDetailId);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        #endregion

        #region "REPORT"

        public List<vIncome> SelectIncomeByDate(DateTime pBookingDateFrom, DateTime pBookingDateTo)
        {
            try
            {
                return _report.SelectIncomeByDate(pBookingDateFrom, pBookingDateTo);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public List<vReportCustomerCheck> ReportCustomerCheck()
        {
            try
            {
                return _report.ReportCustomerCheck();
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        #endregion
    }


    [ServiceContract]
    public interface IManagerService
    {
        #region EMPLOYEE Management

        [OperationContract]
        bool EmployeeEmailCheck(string email);

        [OperationContract]
        bool EmployeeAdd(string name, bool sex, DateTime birthday, string position, string phone, string email,
                         string address, string city, string country, string jobtitle, byte[] image);

        [OperationContract]
        bool EmployeeModify(int employeeID, string name, bool sex, DateTime birthday, string position,
                            string phone, string email, string address, string city, string country, string jobtitle,
                            byte[] image);

        [OperationContract]
        bool EmployeeDeactive(int employeeID);

        [OperationContract]
        List<vEmployeeSubDetail> EmployeesGet(bool all);

        [OperationContract]
        Employee EmployeeGetById(int employeeID);

        [OperationContract]
        List<vEmployeeSubDetail> EmployeesGetByName(string employeeName);

        #endregion

        #region EQUIPMENT Management

        [OperationContract]
        bool EquipmentDetailAdd(string name, decimal price, bool available);

        [OperationContract]
        List<EquipmentDetail> EquipmentDetailsGet(bool available);

        [OperationContract]
        EquipmentDetail EquipmentDetailGetById(int equipmentId);

        [OperationContract]
        List<EquipmentDetail> EquipmentDetailsGetByName(string name);

        [OperationContract]
        bool EquipmentDetailModify(int id, string name, decimal price, bool available);

        #endregion

        #region ROOM Management

        [OperationContract]
        RoomType RoomTypeGetById(int roomTypeId);

        [OperationContract]
        List<RoomType> RoomTypeGets();

        [OperationContract]
        List<EquipmentDetail> EquipmentDetailsGetByRoomTypeID(int roomTypeId);

        [OperationContract]
        bool RoomTypeAdd(string title, string rank, decimal price, bool bath, bool view, bool balcon,
                         List<int> equipmentDetailID);

        [OperationContract]
        bool RoomTypeModify(int id, string title, string rank, decimal price, bool bath, bool view,
                            bool balcony, List<int> equipmentDetailId);

        [OperationContract]
        List<Room> RoomsGet(int available);

        [OperationContract]
        Room RoomGetById(int roomId);

        [OperationContract]
        List<Room> RoomsGetByRoomTypeId(int roomTypeId);

        [OperationContract]
        bool RoomAdd(int roomId, int status, int roomTypeId);

        [OperationContract]
        bool RoomModify(int roomId, int status, int roomTypeId);

        #endregion

        #region "SUPPLY Management"

        [OperationContract]
        bool SupplyDetailAdd(bool available, string supplyName, decimal price, string unit);

        [OperationContract]
        bool SupplyDetailModify(int id, bool available, string supplyName, decimal price, string unit);

        [OperationContract]
        List<SupplyDetail> SupplyDetailsGet(bool available);

        [OperationContract]
        SupplyDetail SupplyDetailGetById(int supplyId);

        [OperationContract]
        List<SupplyDetail> SupplyDetailsGetByName(string supplyDetailName);

        #endregion

        #region "PROMOTION Management"

        [OperationContract]
        List<vSubPromotion> PromotionsGet(bool available);

        [OperationContract]
        Promotion PromotionGetById(int promotionId);

        [OperationContract]
        List<vSubPromotion> PromotionsGetByTitle(string promotionTitle);

        [OperationContract]
        List<vSubPromotion> PromotionsGetByTime(DateTime startTime, DateTime endTime);

        [OperationContract]
        bool PromotionAdd(DateTime startTime, DateTime endTime, string title, string desciption, byte[] banner);

        [OperationContract]
        bool PromotionModify(int promotionId, DateTime startTime, DateTime endTime, string title, string desciption,
                             byte[] banner);

        [OperationContract]
        bool PromotionRemove(int id);

        [OperationContract]
        List<vSubPromotionDetail> PromotionDetailsGetByPromotionId(int promotionId);

        [OperationContract]
        PromotionDetail PromotionDetailGetById(int promotionDetailId);

        [OperationContract]
        bool PromotionDetailAdd(int promotionId, string promotionContent, byte[] promotionImage);

        [OperationContract]
        bool PromotionDetailModify(int promotionDetailId, string promotionContent, byte[] promotionImage);

        [OperationContract]
        bool PromotionDetailRemove(int promotionDetailId);

        #endregion

        #region "REPORT"

        [OperationContract]
        List<vIncome> SelectIncomeByDate(DateTime pBookingDateFrom, DateTime pBookingDateTo);

        [OperationContract]
        List<vReportCustomerCheck> ReportCustomerCheck();

        #endregion
    }
}